#include "gauge.h"

static lv_style_t main_style;
static lv_style_t backgrount_style;

void gauge_set_angle(gauge_t *gauge, uint16_t angle)
{
    if(angle > 360)
    {
        angle = 360;
    }
    lv_arc_set_angles(gauge->main, 360-angle, 360);
}

void gauge_set_size(gauge_t *gauge, lv_coord_t size)
{
    lv_obj_set_size(gauge->backgrount, size, size);
    lv_obj_set_size(gauge->main, size, size);
    lv_obj_realign(gauge->backgrount);
}

void gauge_style_init(void)
{

    lv_style_copy(&backgrount_style, &lv_style_pretty_color);
    backgrount_style.body.opa = 200;
    backgrount_style.line.width = 9;
    backgrount_style.line.rounded = 0;
    backgrount_style.line.opa = 200;
    backgrount_style.line.color = LV_COLOR_WHITE;
    backgrount_style.body.main_color = backgrount_style.line.color;
    backgrount_style.body.grad_color = backgrount_style.line.color;

    lv_style_copy(&main_style, &lv_style_pretty_color);
    main_style.line.width = 10;
    main_style.line.rounded = 1;
    main_style.line.color = LV_COLOR_MAKE(220,87,18);
}

gauge_t  gauge_create(lv_obj_t *parent)
{
    gauge_t ret;

    ret.backgrount = lv_arc_create(parent, NULL);
    lv_arc_set_style(ret.backgrount, LV_ARC_STYLE_MAIN, &backgrount_style);
    lv_arc_set_angles(ret.backgrount, 0, 360);
    
    ret.main = lv_arc_create(ret.backgrount, NULL);
    lv_arc_set_style(ret.main, LV_ARC_STYLE_MAIN, &main_style);
    lv_arc_set_angles(ret.main, 300, 360);
    lv_obj_align_origo(ret.backgrount, ret.main, LV_ALIGN_CENTER, 0, 0);

    return ret;
}